<?php if (!defined("_ECRIRE_INC_VERSION")) return; if (class_exists('AlohacartShippingWeight')) return;
/**
 * Aloha Cart
 *
 * @author     Aleksey Yaroshchuk (aleksey.yaroshchuk@gmail.com)
 * @license    GNU/GPL
 * @package    plugins
 * @subpackage alohacart
 * @copyright  (c) Aleksey Yaroshchuk 2011-2012
 * @link       http://www.spip-contrib.net/AlohaCart
 */

/** 
 *  This class provides flat shipping logic
 *
 *  @author Aleksey Yaroshchuk (aleksey.yaroshchuk@gmail.com)
 */
include_spip('functions/pdk_common');
pdk_load_class('AlohacartExtension', 'classes'); 
class AlohacartShippingWeight extends AlohacartExtension {
    public $fields = array('rate');
    
    public function __construct() {
        parent::__construct();
        $this->configExtension();
    }
    
    private function configExtension(){
        $this->type = 'shipping';
        $this->code = 'weight';
        
        // Define validation rules:         
         $this->validation->set_rules( 
            array(
               array(
                     'field'   => 'rate',
                     'label'   => _T('alohacart_shipping_weight:rate'),
                     'rules'   => 'required'
                  ),
            )
         );
    }
    
    public function GetCost() {
        $data = $this->GetMetaData();
        // Тут все намного сложнее
        $cost = isset($data['rate'])?$data['rate']:0;
        return $cost; 
    }
    
    public function GetData() {        
        $cost = $this->GetCost();        
        return $cost;
    }
}
?>